package com.ahuan.controller;


import com.ahuan.domain.LoginTop;
import com.ahuan.exception.BusinessException;
import com.ahuan.resp.Res;
import com.ahuan.service.StatisticService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/statistic")
public class StatisticController {

    @Autowired
    StatisticService service;


    @GetMapping("loginTop")
    public Res getLoginTop() {
        try {
            log.info("请求获取登录次数最多的前几名用户");
            List<LoginTop> list = service.queryLoginTop();
            if(list!= null && list.size() > 0){
                return Res.successOperate(list);
            }
            return Res.failOperate();
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("获取登录Top5用户失败");
        }
    }

}
